home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1992, 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
-
- #include <stdio.h>
- #include <X11/X.h>
- #include <X11/Xlib.h>
- #include <Xm/Xm.h>
- #include <X11/Intrinsic.h>
- #include <X11/Xirisw/GlxMDraw.h>
- #include <X11/keysym.h>
- #include </usr/include/X11/Xm/XmP.h>
- #include "copycmap.h"
-
- #define DRAW 1
- #define ERASE 2
-
- /* information for setting up colormap */
- static Colorindex red, green, yellow, blue, magenta, cyan;
- static Colorindex background;
- /* The following structure is declared in copycmap.h and is used by
- * CopyGlColormap (in this demo directory) to set up a clormap
- * with the specified colors. Note that while we are using GLXC_NAMED
- * to look up named colors, we could also use GLXC_ABSOLUTE and specify
- * hardcoded pixel numbers 1-6 to copy from the X colormap.
- */
- struct glxcColorInfo colorInfo[] =
- {
- { GLXC_NAMED, (caddr_t)"red", &red},
- { GLXC_NAMED, (caddr_t)"green", &green},
- { GLXC_NAMED, (caddr_t)"yellow", &yellow},
- { GLXC_NAMED, (caddr_t)"blue", &blue},
- { GLXC_NAMED, (caddr_t)"magenta", &magenta},
- { GLXC_NAMED, (caddr_t)"cyan", &cyan},
- { GLXC_RESOURCE, (caddr_t)XmNbackground, &background},
- };
-
-
- static GLXconfig glxConfigZSize = { GLX_NORMAL, GLX_ZSIZE, GLX_NOCONFIG };
- static GLXconfig glxConfigRGB = {GLX_NORMAL, GLX_RGB, TRUE };
- static GLXconfig glxConfigDblBuf = {GLX_NORMAL, GLX_DOUBLE, TRUE };
- static GLXconfig glxConfigOverlay = {GLX_OVERLAY, GLX_BUFSIZE, 2 };
- static GLXconfig glxConfigPopup = {GLX_POPUP, GLX_BUFSIZE, 2 };
- static GLXconfig glxConfig [] = {
- { 0, 0, 0 },
- { 0, 0, 0 },
- { 0, 0, 0 },
- { 0, 0, 0 },
- { 0, 0, 0 }
- };
- static int usePups;
- static Widget glw;
- static int buttonDown;
- static void initCB();
-
- /*
- * Return the overlay window of the widget
- * w - The GL widget
- */
- Window
- overlayWindow(w)
- Widget w;
- {
- Arg args[1];
- Window overlayWindow;
-
- XtSetArg(args[0], usePups?GlxNpopupWindow:GlxNoverlayWindow,
- &overlayWindow);
- XtGetValues(w, args, 1);
- return (overlayWindow);
- }
-
- /*
- * drawOverlayLine - Draw or erase an overlay line from x1,y1 to x2,y2
- */
-
- drawOverlayLine(drawOrErase, x1, y1, x2, y2)
- int drawOrErase;
- int x1, y1, x2, y2;
- {
- long vector1[2];
- long vector2[2];
-
- /*
- * The y values need conversion from X land to GL land.
- */
- vector1[0] = x1;
- vector1[1] = XtWidth(glw) - y1;
- vector2[0] = x2;
- vector2[1] = XtWidth(glw) - y2;
-
- GLXwinset(XtDisplay(glw), overlayWindow(glw));
- if (drawOrErase == DRAW) {
- /*
- * Draw a rubber band line in the overlay planes
- */
- color(1);
- } else if (drawOrErase == ERASE) {
- /*
- * Erase a rubber band line in the overlay planes
- */
- color(0);
- } else {
- return;
- }
- bgnline();
- v2i(vector1);
- v2i(vector2);
- endline();
- }
-
-
- /* Callbacks */
- static void
- exposeCB(w, client_data, call_data)
- Widget w;
- caddr_t client_data;
- caddr_t call_data;
- {
- GLXwinset(XtDisplay(w), XtWindow(w));
- color(background);
- clear();
- }
-
- int anchorX;
- int anchorY;
- int oldX;
- int oldY;
- /*
- * This is the input callback for the GL window. Any button will
- * Activate rubber-banding. The rubber band line will follow the
- * mouse until the button is let up.
- */
- GLInputCB(w, client_data, call_data)
- Widget w;
- caddr_t client_data;
- GlxDrawCallbackStruct *call_data;
- {
-
- XEvent *InputEvent;
-
- InputEvent = call_data->event;
- switch (InputEvent->type) {
- case ButtonPress:
- anchorX = InputEvent->xbutton.x;
- anchorY = InputEvent->xbutton.y;
- oldX = anchorX;
- oldY = anchorY;
- buttonDown = 1;
- break;
- case MotionNotify:
- if (buttonDown == 1) {
- drawOverlayLine(ERASE, anchorX, anchorY,
- oldX, oldY);
- drawOverlayLine(DRAW, anchorX, anchorY,
- InputEvent->xbutton.x, InputEvent->xbutton.y);
- oldX = InputEvent->xbutton.x;
- oldY = InputEvent->xbutton.y;
- }
- break;
- }
- }
-
- /* GL initialization; extracted from the original main() */
- static void
- initialize_gl() {
-
- short data;
- float scrnaspect; /* aspect ratio value */
- long xscrnsize; /* size of screen in x used to set globals */
-
-
- xscrnsize = getgdesc(GD_XPMAX); /* get/set screen size[/aspect] */
- if (xscrnsize == 1280) {
- keepaspect(5, 4);
- scrnaspect = 1.25;
- } else if (xscrnsize = 1023) {
- keepaspect(4, 3);
- scrnaspect = 1.34;
- } else {
- fprintf(stderr, "Something's EXTREMELY wrong: ");
- fprintf(stderr, "xscrnsize=%d\n", xscrnsize);
- exit(-1) ;
- }
-
- /* initialize and set the display to double buffer mode */
-
- doublebuffer();
- writemask((1<<getplanes())-1);
- }
-
- /*
- * Thanks to 4DGifts for this routine.
- * This routine will install a particular gl widgets's colormap onto the
- * top level window. It may not be called until after the windows have
- * been realized.
- */
- installColormap(toplevel, glw)
- Widget toplevel, glw;
- {
- Window windows[2];
-
- windows[0] = XtWindow(glw);
- windows[1] = XtWindow(toplevel);
- XSetWMColormapWindows(XtDisplay(toplevel), XtWindow(toplevel), windows, 2);
- }
-
- static void
- initCB(w, client_data, call_data)
- Widget w;
- caddr_t client_data;
- caddr_t call_data;
- {
- GLXwinset(XtDisplay(w), XtWindow(w));
- CopyGlColormap(w, colorInfo, XtNumber(colorInfo));
- color(background);
- initialize_gl();
- clear();
- gflush();
- }
-
- /*
- * Thanks to 4DGifts for this routine.
- * This routine is similar to installColormap (in the file installcmap.c)
- * excepth that it weill also install any auxiliary (overlay, popup and
- * underlay) windows onto the top level window. It may not be called
- * until after the windows have been realized.
- */
- installColormapWithOverlay(toplevel, glw)
- Widget toplevel, glw;
- {
- Window windows[5];
- Window overlay, popup, underlay;
- Arg args[5];
- register int i=0;
-
- i=0;
- XtSetArg(args[i], GlxNoverlayWindow, &overlay); i++;
- XtSetArg(args[i], GlxNpopupWindow, &popup); i++;
- XtSetArg(args[i], GlxNunderlayWindow, &underlay); i++;
- XtGetValues(glw, args, i);
- i = 0;
- if (overlay)
- {
- windows[i] = overlay;
- i++;
- }
- if (popup)
- {
- windows[i] = popup;
- i++;
- }
- if (underlay)
- {
- windows[i] = underlay;
- i++;
- }
- windows[i] = XtWindow(glw); i++;
- windows[i] = XtWindow(toplevel); i++;
- XSetWMColormapWindows(XtDisplay(toplevel), XtWindow(toplevel), windows, i);
- }
-
-
- /*
- * initializeGLOverlayWindow - Returns the GL widget with the
- * overlay window enabled.
- *
- * parent = The widget's parent widget
- */
-
- Widget
- initGLWidgetWithOverlay(Widget parent)
- {
- int numArgs; /* The number of arguments passed to XtCreateManagedWidget */
- Arg args[10]; /* The argument list passed to XtCreateManagedWidget */
- int configArgNum = 0;
-
- /*
- * Set up the glxConfig structure for double buffered, RGB mode.
- */
- glxConfig[configArgNum++] = glxConfigDblBuf;
-
- /*
- * Determine wether overlay planes are available. If not, use
- * popup planes
- */
- if (getgdesc(GD_BITS_OVER_SNG_CMODE) < 2) {
- usePups = 1;
- glxConfig[configArgNum++] = glxConfigPopup;
- } else {
- glxConfig[configArgNum++] = glxConfigOverlay;
- }
-
-
- /*
- * Set up the arg structure for creation of the GL window
- */
- numArgs = 0;
- XtSetArg(args[numArgs], GlxNglxConfig, glxConfig);
- numArgs++;
- XtSetArg(args[numArgs], usePups?GlxNusePopup:GlxNuseOverlay, TRUE);
- numArgs++;
-
- /*
- * Create the GL widget
- */
- glw = XtCreateManagedWidget("glwidget", glxMDrawWidgetClass, parent,
- args, numArgs);
-
- /*
- * Set up callback for the GL window
- */
- XtAddCallback(glw, GlxNexposeCallback, exposeCB, 0);
- XtAddCallback(glw, GlxNinputCallback, GLInputCB, 0);
- XtAddCallback(glw, GlxNginitCallback, initCB, 0);
- return(glw);
- }
-
-